<template>
  <div class="course-card">
    <div class="card-img-container">
      <img
        :src="course.coverImage"
        :alt="course.title"
        @error="handleImageError"
      />
      <div class="course-stats">
        <span><i class="fas fa-heart"></i> {{ course.favoriteCount }}</span>
        <span><i class="fas fa-comment"></i> {{ course.reviewCount }}</span>
        <span><i class="fas fa-thumbs-up"></i> {{ course.likeCount }}</span>
      </div>
    </div>
    <div class="card-content">
      <h3 :title="course.title">{{ course.title }}</h3>
      <p :title="course.description" class="course-description">
        {{ course.description }}
      </p>
      <div class="course-meta">
        <div class="teacher">
          <i class="fas fa-user"></i>
          <span>{{ course.consultantName }}</span>
        </div>
        <div class="time">
          <i class="fas fa-clock"></i>
          <span>{{ course.startTime }}</span>
        </div>
      </div>
      <router-link :to="`/courses/${course.id}`" class="view-btn">
        查看详情
        <i class="fas fa-arrow-right"></i>
      </router-link>
    </div>
  </div>
</template>

<script setup lang="ts">
import { type CourseInfoVO } from "@/api/course";

defineProps<{
  course: CourseInfoVO;
}>();

const handleImageError = (e: Event) => {
  const img = e.target as HTMLImageElement;
  img.src = "https://via.placeholder.com/300x200/f0f0f0/666666?text=暂无图片";
};
</script>

<style scoped>
.course-card {
  background-color: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.course-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.card-img-container {
  position: relative;
  width: 100%;
  height: 160px;
  overflow: hidden;
}

.card-img-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.course-card:hover .card-img-container img {
  transform: scale(1.05);
}

.course-stats {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  color: white;
  display: flex;
  gap: 16px;
  font-size: 12px;
}

.course-stats span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-content {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  text-align: left;
}

h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: #333;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  height: 44px;
  text-align: left;
}

.course-description {
  color: #666;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  height: 38px;
  text-align: left;
}

.course-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  color: #666;
  font-size: 12px;
}

.teacher,
.time {
  display: flex;
  align-items: center;
  gap: 4px;
}

.view-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background-color: #007bff;
  color: white;
  padding: 8px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 500;
  margin-top: auto;
  transition: all 0.3s ease;
  font-size: 13px;
}

.view-btn:hover {
  background-color: #0056b3;
}

.view-btn i {
  transition: transform 0.3s ease;
}

.view-btn:hover i {
  transform: translateX(4px);
}

@media (max-width: 768px) {
  .card-img-container {
    height: 140px;
  }

  h3 {
    font-size: 15px;
    height: 42px;
  }

  .course-description {
    font-size: 12px;
    height: 36px;
  }
}
</style>
